<template>
  <div>
    <el-dialog :title='title' :visible.sync="dialogFormVisible" @closed="$emit('update:activated', false)"
               width="750px">
      <el-card>
        <div class="dialogStyle" style="display: flex;flex-direction: column">
          <el-form  class="search-form search-form-normal" label-width="110px" ref="form"
                    style="flex: 5" :model="form" size="mini" :rules="rules">
            <el-form-item :label="$t('pageTable.OrderInfoOrderCode')" prop="orderCode">
              <el-autocomplete v-model="form.orderCode" :disabled="mode ==='EDIT'" class="search-form-item-input" style="width: 160px" size="mini"
                            :fetch-suggestions="searchOrderCode"    clearable></el-autocomplete>
              <template slot="error" slot-scope="scope">
                <div style="float: right;margin-right: 30px;font-size: 10px;color: red">{{scope.error}}</div>
              </template>
              <div style="float: right;margin-right: 40px;"><el-button :disabled="form.orderCode==''" @click="checkOrderCode(form.orderCode)">{{$t('searchFrom.checkAndGet')}}</el-button></div>
            </el-form-item>
            <el-form-item :label="$t('pageTable.OrderInfoOrderCodeDesc')" prop="orderCodeDesc">
              <el-input type="textarea" autosize="" v-model="form.orderCodeDesc" class="search-form-item-input" style="width: 160px" size="mini"
                        clearable></el-input>
              <template slot="error" slot-scope="scope">
                <div style="float: right;margin-right: 100px;font-size: 10px;color: red">{{scope.error}}</div>
              </template>
            </el-form-item>
            <el-form-item :label="$t('pageTable.OrderInfoOrderAmount')" prop="orderAmount">
              <el-input v-model="form.orderAmount" class="search-form-item-input" style="width:160px" size="mini"
                         :maxlength="18" clearable></el-input>
              <template slot="error" slot-scope="scope">
                <div style="float: right;margin-right: 100px;font-size: 10px;color: red">{{scope.error}}</div>
              </template>
            </el-form-item>
            <el-form-item :label="$t('pageTable.OrderInfoOrderDate')" prop="orderDate">
              <el-date-picker
                v-model="form.orderDate"
                type="date"
                style="width:160px"
                value-format="yyyyMMddHHmmss">
              </el-date-picker>
              <template slot="error" slot-scope="scope">
                <div style="float: right;margin-right: 100px;font-size: 10px;color: red">{{scope.error}}</div>
              </template>
            </el-form-item>
            <el-form-item :label="$t('pageTable.OrderInfoOrderUnit')" prop="orderUnit">
              <el-select  v-model="form.orderUnit" style="width: 160px" size="mini" clearable>
                <el-option value=""></el-option>
                <el-option
                  size="mini"
                  v-for="item in orderUnits"
                  :key="item.value"
                  :label="item.name"
                  :value="item.value">
                </el-option>
              </el-select>
              <template slot="error" slot-scope="scope">
                <div style="float: right;margin-right: 100px;font-size: 10px;color: red">{{scope.error}}</div>
              </template>
            </el-form-item>
            <el-form-item :label="$t('pageTable.orderNo')" prop="orderId">
              <el-input v-model="form.orderId" class="search-form-item-input" style="width:160px" size="mini"
                        :disabled="true"  :placeholder="$t('pageTable.AutomaticGeneration')"  :maxlength="20"  clearable></el-input>
              <template slot="error" slot-scope="scope">
                <div style="float: right;margin-right: 100px;font-size: 10px;color: red">{{scope.error}}</div>
              </template>
            </el-form-item>
            <el-form-item :label="$t('pageTable.orderIdItem')" prop="orderIdItem">
              <el-input v-model="form.orderIdItem" class="search-form-item-input" style="width:160px" size="mini"
                        :disabled="true"  :placeholder="$t('pageTable.AutomaticGeneration')"  :maxlength="5" clearable></el-input>
              <template slot="error" slot-scope="scope">
                <div style="float: right;margin-right: 100px;font-size: 10px;color: red">{{scope.error}}</div>
              </template>
            </el-form-item>
            <el-form-item :label="$t('pageTable.MatterMaterialSpecificNumber')" prop="materialCode">
              <el-autocomplete v-model="form.materialCode" class="search-form-item-input" style="width:160px" size="mini"
                               :fetch-suggestions="searchMaterialCode" clearable></el-autocomplete>
              <template slot="error" slot-scope="scope">
                <div style="float: right;margin-right: 30px;font-size: 10px;color: red">{{scope.error}}</div>
              </template>
              <div style="float: right;margin-right: 40px;"><el-button :disabled="form.materialCode==''" @click="checkMaterialCode(form.materialCode)">{{$t('searchFrom.checkAndGet')}}</el-button></div>

            </el-form-item>
            <el-form-item :label="$t('pageTable.MatterChineseDescriptionOfMaterials')" prop="materialDescCn">
              <el-input type="textarea" v-model="form.materialDescCn" class="search-form-item-input" style="width:160px" size="mini"
                        clearable></el-input>
              <template slot="error" slot-scope="scope">
                <div style="float: right;margin-right: 100px;font-size: 10px;color: red">{{scope.error}}</div>
              </template>
            </el-form-item>
            <el-form-item :label="$t('pageTable.MatterEnglishDescriptionOfMaterials')" prop="materialDescEn">
              <el-input type="textarea" v-model="form.materialDescEn" class="search-form-item-input" style="width:160px" size="mini"
                          clearable></el-input>
              <template slot="error" slot-scope="scope">
                <div style="float: right;margin-right: 100px;font-size: 10px;color: red">{{scope.error}}</div>
              </template>
            </el-form-item>
            <el-form-item :label="$t('pageTable.MatterRussianDescriptionOfMaterials')" prop="materialDescRn">
              <el-input type="textarea" v-model="form.materialDescRn" class="search-form-item-input" style="width:160px" size="mini"
                          clearable></el-input>
              <template slot="error" slot-scope="scope">
                <div style="float: right;margin-right: 100px;font-size: 10px;color: red">{{scope.error}}</div>
              </template>
            </el-form-item>
            <!--materialSupplierNo-->
            <el-form-item :label="$t('pageTable.SupplierCode')" prop="materialSupplierNo">
              <el-input v-model="form.materialSupplierNo" class="search-form-item-input" style="width:160px" size="mini"
                        clearable></el-input>
              <template slot="error" slot-scope="scope">
                <div style="float: right;margin-right: 100px;font-size: 10px;color: red">{{scope.error}}</div>
              </template>
            </el-form-item>
            <el-form-item :label="$t('pageTable.MatterCompany')" prop="materialUnit">
              <el-select  v-model="form.materialUnit" style="width: 160px" size="mini" clearable>
                <el-option value=""></el-option>
                <el-option
                  size="mini"
                  v-for="item in materialUnit"
                  :key="item.value"
                  :label="item.name"
                  :value="item.value">
                </el-option>
              </el-select>
              <template slot="error" slot-scope="scope">
                <div style="float: right;margin-right: 100px;font-size: 10px;color: red">{{scope.error}}</div>
              </template>
            </el-form-item>
            <el-form-item :label="$t('pageTable.MatterSpecificConsumption')" prop="materialAmount">
              <el-input v-model="form.materialAmount" class="search-form-item-input" style="width:160px" size="mini"
                          :maxlength="18" clearable></el-input>
              <template slot="error" slot-scope="scope">
                <div style="float: right;margin-right: 100px;font-size: 10px;color: red">{{scope.error}}</div>
              </template>
            </el-form-item>
            <el-form-item :label="$t('pageTable.MatterChannel')" prop="materialCategory">
              <el-select  v-model="form.materialCategory" style="width: 160px" size="mini" clearable>
                <el-option value=""></el-option>
                <el-option
                  size="mini"
                  v-for="item in materialCategory"
                  :key="item.value"
                  :label="item.name"
                  :value="item.value">
                </el-option>
              </el-select>
              <template slot="error" slot-scope="scope">
                <div style="float: right;margin-right: 100px;font-size: 10px;color: red">{{scope.error}}</div>
              </template>
            </el-form-item>
            <el-form-item :label="$t('pageTable.MatterConversionRelationship')" prop="materialRelation">
              <el-input v-model="form.materialRelation" class="search-form-item-input" style="width:160px" size="mini"
                         clearable></el-input>
              <template slot="error" slot-scope="scope">
                <div style="float: right;margin-right: 100px;font-size: 10px;color: red">{{scope.error}}</div>
              </template>
            </el-form-item>
            <el-form-item :label="$t('pageTable.MatterConvertedUnit')" prop="materialRelationUnit">
              <el-select  v-model="form.materialRelationUnit" style="width: 160px" size="mini" clearable>
                <el-option value=""></el-option>
                <el-option
                  size="mini"
                  v-for="item in materialRelationUnit"
                  :key="item.value"
                  :label="item.name"
                  :value="item.value">
                </el-option>
              </el-select>
              <template slot="error" slot-scope="scope">
                <div style="float: right;margin-right: 100px;font-size: 10px;color: red">{{scope.error}}</div>
              </template>
            </el-form-item>
            <el-form-item :label="$t('pageTable.ConvertedQuantity')" prop="materialRelationQuantity">
              <el-input v-model="form.materialRelationQuantity" class="search-form-item-input" style="width:160px" size="mini"
                         :maxlength="18" clearable></el-input>
              <template slot="error" slot-scope="scope">
                <div style="float: right;margin-right: 100px;font-size: 10px;color: red">{{scope.error}}</div>
              </template>
            </el-form-item>
<!--            <el-form-item :label="最小包装类型" prop="materialMinpackageType">-->
<!--              <el-select :disabled="true" v-model="form.materialMinpackageType" style="width: 160px" size="mini" clearable>-->
<!--                <el-option value=""></el-option>-->
<!--                <el-option-->
<!--                  size="mini"-->
<!--                  v-for="item in materialMinpackageType"-->
<!--                  :key="item.value"-->
<!--                  :label="item.name"-->
<!--                  :value="item.value">-->
<!--                </el-option>-->
<!--              </el-select>-->
<!--              <template slot="error" slot-scope="scope">-->
<!--                <div style="float: right;margin-right: 100px;font-size: 10px;color: red">{{scope.error}}</div>-->
<!--              </template>-->
<!--            </el-form-item>-->
<!--            <el-form-item :label="最小包装数量" prop="materialMinpackageAmt">-->
<!--              <el-input v-model="form.materialMinpackageAmt" class="search-form-item-input" style="width:160px" size="mini"-->
<!--                        :disabled="true"   :maxlength="18"  clearable></el-input>-->
<!--              <template slot="error" slot-scope="scope">-->
<!--                <div style="float: right;margin-right: 100px;font-size: 10px;color: red">{{scope.error}}</div>-->
<!--              </template>-->
<!--            </el-form-item>-->
<!--            <el-form-item :label="最小包装总量" prop="materialMinpackageTotalamt">-->
<!--              <el-input v-model="form.materialMinpackageTotalamt" class="search-form-item-input" style="width:160px" size="mini"-->
<!--                        :disabled="form.orderCode==''"   :maxlength="18"  clearable></el-input>-->
<!--              <template slot="error" slot-scope="scope">-->
<!--                <div style="float: right;margin-right: 100px;font-size: 10px;color: red">{{scope.error}}</div>-->
<!--              </template>-->
<!--            </el-form-item>-->
            <el-form-item :label="$t('pageTable.MatterUntaxedUnitPrice')" prop="materialTaxPrice">
              <el-input v-model="form.materialTaxPrice" class="search-form-item-input" style="width:160px" size="mini"
                         :maxlength="18"   clearable></el-input>
              <template slot="error" slot-scope="scope">
                <div style="float: right;margin-right: 100px;font-size: 10px;color: red">{{scope.error}}</div>
              </template>
            </el-form-item>
            <el-form-item :label="$t('pageTable.materialTaxTotalprice')" prop="materialTaxTotalprice">
            <el-input v-model="form.materialTaxTotalprice" class="search-form-item-input" style="width:160px" size="mini"
                      :maxlength="18"   clearable></el-input>
            <template slot="error" slot-scope="scope">
              <div style="float: right;margin-right: 100px;font-size: 10px;color: red">{{scope.error}}</div>
            </template>
          </el-form-item>
            <el-form-item :label="$t('pageTable.MatterTaxRate')" prop="tax">
              <el-input v-model="form.tax" class="search-form-item-input" style="width:160px" size="mini"
                        :maxlength="18"   clearable></el-input>
              <template slot="error" slot-scope="scope">
                <div style="float: right;margin-right: 100px;font-size: 10px;color: red">{{scope.error}}</div>
              </template>
            </el-form-item>
            <el-form-item :label="$t('pageTable.MatterUnitPriceWithTax')" prop="materialVatPrice">
              <el-input v-model="form.materialVatPrice" class="search-form-item-input" style="width:160px" size="mini"
                         :maxlength="18"  clearable></el-input>
              <template slot="error" slot-scope="scope">
                <div style="float: right;margin-right: 100px;font-size: 10px;color: red">{{scope.error}}</div>
              </template>
            </el-form-item>
            <el-form-item :label="$t('pageTable.materialVatTotalprice')" prop="materialVatTotalprice">
              <el-input v-model="form.materialVatTotalprice" class="search-form-item-input" style="width:160px" size="mini"
                          :maxlength="18"  clearable></el-input>
              <template slot="error" slot-scope="scope">
                <div style="float: right;margin-right: 100px;font-size: 10px;color: red">{{scope.error}}</div>
              </template>
            </el-form-item>
            <el-form-item :label="$t('pageTable.MatterAgencyRate')" prop="materialRate">
              <el-input v-model="form.materialRate" class="search-form-item-input" style="width:160px" size="mini"
                         :maxlength="18"  clearable></el-input>
              <template slot="error" slot-scope="scope">
                <div style="float: right;margin-right: 100px;font-size: 10px;color: red">{{scope.error}}</div>
              </template>
            </el-form-item>
            <el-form-item :label="$t('pageTable.MatterCurrency')" prop="materialCurrency">
              <el-select  v-model="form.materialCurrency" style="width: 160px" size="mini" clearable>
                <el-option value=""></el-option>
                <el-option
                  size="mini"
                  v-for="item in materialCurrency"
                  :key="item.value"
                  :label="item.name"
                  :value="item.value">
                </el-option>
              </el-select>
              <template slot="error" slot-scope="scope">
                <div style="float: right;margin-right: 100px;font-size: 10px;color: red">{{scope.error}}</div>
              </template>
            </el-form-item>
            <el-form-item :label="$t('pageTable.countryCode')" prop="countryCode">
              <el-select  v-model="form.countryCode" style="width: 160px" size="mini" clearable>
                <el-option value=""></el-option>
                <el-option
                  size="mini"
                  v-for="item in countryCode"
                  :key="item.value"
                  :label="item.name"
                  :value="item.value">
                </el-option>
              </el-select>
              <template slot="error" slot-scope="scope">
                <div style="float: right;margin-right: 100px;font-size: 10px;color: red">{{scope.error}}</div>
              </template>
            </el-form-item>
            <el-form-item :label="$t('pageTable.goodsStatus')" prop="confirmStatus">
              <el-select  v-model="form.confirmStatus" style="width: 160px" size="mini" clearable>
                <el-option value=""></el-option>
                <el-option
                  size="mini"
                  v-for="item in confirmStatus"
                  :key="item.value"
                  :label="item.name"
                  :value="item.value">
                </el-option>
              </el-select>
              <template slot="error" slot-scope="scope">
                <div style="float: right;margin-right: 100px;font-size: 10px;color: red">{{scope.error}}</div>
              </template>
            </el-form-item>
            <el-form-item :label="$t('pageTable.orderDetailType')" prop="orderDetailType">
              <el-select  :disabled="true" v-model="form.orderDetailType" style="width: 160px" size="mini" clearable>
                <el-option value=""></el-option>
                <el-option
                        size="mini"
                        v-for="item in orderDetailType"
                        :key="item.value"
                        :label="item.name"
                        :value="item.value">
                </el-option>
              </el-select>
              <template slot="error" slot-scope="scope">
                <div style="float: right;margin-right: 100px;font-size: 10px;color: red">{{scope.error}}</div>
              </template>
            </el-form-item>
<!--            <el-form-item :label="型号发货总数量" prop="orderOutTotalAmount">-->
<!--              <el-input v-model="form.orderOutTotalAmount" class="search-form-item-input" style="width:160px" size="mini"-->
<!--                        :disabled="form.orderCode==''"  :maxlength="18"  clearable></el-input>-->
<!--              <template slot="error" slot-scope="scope">-->
<!--                <div style="float: right;margin-right: 100px;font-size: 10px;color: red">{{scope.error}}</div>-->
<!--              </template>-->
<!--            </el-form-item>-->
<!--            <el-form-item :label="子件发货总数量" prop="materOutTotalAmount">-->
<!--              <el-input v-model="form.materOutTotalAmount" class="search-form-item-input" style="width:160px" size="mini"-->
<!--                        :disabled="form.orderCode==''"   :maxlength="18"  clearable></el-input>-->
<!--              <template slot="error" slot-scope="scope">-->
<!--                <div style="float: right;margin-right: 100px;font-size: 10px;color: red">{{scope.error}}</div>-->
<!--              </template>-->
<!--            </el-form-item>-->
<!--            <el-form-item :label="订单剩余数量" prop="residualAmount">-->
<!--              <el-input v-model="form.residualAmount" class="search-form-item-input" style="width:160px" size="mini"-->
<!--                        :maxlength="18"  clearable></el-input>-->
<!--              <template slot="error" slot-scope="scope">-->
<!--                <div style="float: right;margin-right: 100px;font-size: 10px;color: red">{{scope.error}}</div>-->
<!--              </template>-->
<!--            </el-form-item>-->
            <!--<el-form-item :label="调整后数量" prop="trimAmount">-->
              <!--<el-input v-model="form.trimAmount" class="search-form-item-input" style="width:160px" size="mini"-->
                        <!--:disabled="form.orderCode==''"   :maxlength="18"   clearable></el-input>-->
              <!--<template slot="error" slot-scope="scope">-->
                <!--<div style="float: right;margin-right: 100px;font-size: 10px;color: red">{{scope.error}}</div>-->
              <!--</template>-->
            <!--</el-form-item>-->
<!--            <el-form-item :label="库存数量" prop="stockAmount">-->
<!--              <el-input v-model="form.stockAmount" class="search-form-item-input" style="width:160px" size="mini"-->
<!--                        :disabled="form.orderCode==''"  :maxlength="18"  clearable></el-input>-->
<!--              <template slot="error" slot-scope="scope">-->
<!--                <div style="float: right;margin-right: 100px;font-size: 10px;color: red">{{scope.error}}</div>-->
<!--              </template>-->
<!--            </el-form-item>-->
<!--            <el-form-item :label="差异数量" prop="differAmount">-->
<!--              <el-input v-model="form.differAmount" class="search-form-item-input" style="width:160px" size="mini"-->
<!--                         :maxlength="18"  clearable></el-input>-->
<!--              <template slot="error" slot-scope="scope">-->
<!--                <div style="float: right;margin-right: 100px;font-size: 10px;color: red">{{scope.error}}</div>-->
<!--              </template>-->
<!--            </el-form-item>-->
<!--            <el-form-item :label="收货数量" prop="takeOverAmount">-->
<!--              <el-input v-model="form.takeOverAmount" class="search-form-item-input" style="width:160px" size="mini"-->
<!--                        :maxlength="18"  clearable></el-input>-->
<!--              <template slot="error" slot-scope="scope">-->
<!--                <div style="float: right;margin-right: 100px;font-size: 10px;color: red">{{scope.error}}</div>-->
<!--              </template>-->
<!--            </el-form-item>-->
            <el-form-item :label="$t('pageTable.QuantityOfShipments')" prop="deliveryAmount">
              <el-input v-model="form.deliveryAmount" class="search-form-item-input" style="width:160px" size="mini"
                        :maxlength="18"  clearable></el-input>
              <template slot="error" slot-scope="scope">
                <div style="float: right;margin-right: 100px;font-size: 10px;color: red">{{scope.error}}</div>
              </template>
            </el-form-item>
            <el-form-item :label="$t('pageTable.surplusAmount')" prop="surplusAmount">
              <el-input v-model="form.surplusAmount" class="search-form-item-input" style="width:160px" size="mini"
                        :maxlength="18"  clearable></el-input>
              <template slot="error" slot-scope="scope">
                <div style="float: right;margin-right: 100px;font-size: 10px;color: red">{{scope.error}}</div>
              </template>
            </el-form-item>
          </el-form>
        </div>
      </el-card>
      <div class="dialogButton">
        <el-button type="primary" size="mini" :disabled="form.isLocked==1" @click="submit('form')"><i
          class="fa fa-check"></i>  {{$t('searchFrom.confirm')}}
        </el-button>
        <el-button size="mini" @click=" cancel">{{$t('searchFrom.cancel')}}</el-button>
      </div>

    </el-dialog>
  </div>
</template>

<script>
  import activityService from '@/api/warehouse/planDetail'
  import ui_config from '@/config/ui_config'

  export default {
    name: "EditOrderPlan",
    props: {
      id: {},
      mode: "",
      dateFlag:"",
    },
    computed: {
      title: function () {
        let entityName = this.$t('searchFrom.planDetail')
        if(this.mode === 'ADD'){return this.$t('searchFrom.add')+entityName}
        else if(this.mode === 'EDIT'){return this.$t('searchFrom.edit')+entityName}
      }
    },
    data() {
      return {
        dialogFormVisible: true,
        search_keys: {},
        orderUnits:[],
        materialUnit:[],
        materialCategory:[],
        materialRelationUnit:[],
        materialMinpackageType:[],
        materialCurrency:[],
        countryCode:[],
        confirmStatus:[],
        orderDetailType:[],
        form: {
          orderCode:"",
          orderCodeDesc:"",
          orderAmount:"",
          orderDate:"",
          orderUnit:"",
          orderId:"",
          orderIdItem:"",
          materialCode:"",
          materialDescCn:"",
          materialDescEn:"",
          materialDescRn:"",
          materialSupplierNo:"",
          materialUnit:"",
          materialAmount:"",
          materialCategory:"",
          materialRelation:"",
          materialRelationUnit:"",
          materialRelationQuantity:"",
          materialMinpackageType:"",
          materialMinpackageAmt:"",
          materialMinpackageTotalamt:"",
          materialTaxPrice:"",
          materialTaxTotalprice:"",
          materialVatPrice:"",
          materialVatTotalprice:"",
          materialRate:"",
          materialCurrency:"",
          countryCode:"",
          confirmStatus:"",
          orderDetailType:"",
          orderOutTotalAmount:"",
          materOutTotalAmount:"",
          residualAmount:"",
          trimAmount:"",
          // stockAmount:"",
          differAmount:"",
          takeOverAmount:"",
          deliveryAmount:"",
          surplusAmount:"",
        },
        orderCodeList:[],
        materialCodeList:[],
        /**表单的验证*/
        rules: {
          orderCode: [
            // {required: true, message: '请填写订单型号', trigger: 'blur'},
            {max: 32, message: this.$t('Tips.lentghGT20'), trigger: 'blur'},
            {pattern: /^[a-z|A-Z|0-9|_]+$/, trigger: 'blur', message: this.$t('Tips.formatNames'),}
          ],
          orderCodeDesc: [
            // {required: true, message: '请填写订单型号描述', trigger: 'blur'},
            {max: 200, message: this.$t('Tips.lentghGT200'), trigger: 'blur'}
          ],
          orderAmount: [
            // {required: true, message: '请填写$t('pageTable.OrderInfoOrderAmount')', trigger: 'blur'},
            // {pattern: /^[0-9]*$/ , trigger: 'blur', message: '请输入数字',}
            {pattern:  /^([0-9]*)+\.{0,1}[0-9]{1,3}$/ , trigger: 'blur', message: this.$t('Tips.floatCheck'),}
          ],
          // orderDate:[
          //   {required: true, message: '请填写$t('pageTable.OrderInfoOrderDate')', trigger: 'blur'},
          // ],
          // orderUnit: [
          //   {required: true, message: '请选择订单型号单位', trigger: 'change'}
          // ],
          orderId:[
            {max: 20, message: this.$t('Tips.lentghGT20'), trigger: 'blur'},
          ],
          orderIdItem:[
            {max: 5, message: this.$t('Tips.lentghGT5'), trigger: 'blur'},
          ],
          materialCode: [
            {required: true, message: this.$t('Tips.checkMaterialCode'), trigger: 'blur'},
            {max: 20, message: this.$t('Tips.lentghGT20'), trigger: 'blur'},
          ],
          materialDescCn: [
            {required: true, message: this.$t('Tips.checkMaterialDescCn'), trigger: 'blur'},
            {max: 200, message: this.$t('Tips.lentghGT200'), trigger: 'blur'},
          ],
          materialDescEn: [
            {required: false, message: this.$t('Tips.checkMaterialDescEn'), trigger: 'blur'},
            {max: 200, message: this.$t('Tips.lentghGT200'), trigger: 'blur'},
          ],
          materialDescRn: [
            {required: false, message: this.$t('Tips.checkMaterialDescRn'), trigger: 'blur'},
            {max: 200, message: this.$t('Tips.lentghGT200'), trigger: 'blur'},
          ],
          materialUnit: [
            {required: true, message: this.$t('Tips.checkMaterialUnit'), trigger: 'change'}
          ],
          materialAmount: [
            {required: true, message: this.$t('Tips.checkMaterialAmount'), trigger: 'blur'},
            {pattern:  /^([0-9]*)+\.{0,1}[0-9]{1,3}$/ , trigger: 'blur', message: this.$t('Tips.floatCheck'),}
          ],
          materialCategory: [
            {required: true, message: this.$t('Tips.checkMaterialCategory'), trigger: 'change'}
          ],
          materialRelation: [
            {max: 30, message: this.$t('Tips.lentghGT30'), trigger: 'blur'},
          ],
          materialRelationUnit: [

          ],
          materialRelationQuantity: [
            {pattern:  /^([0-9]*)+\.{0,1}[0-9]{1,6}$/ , trigger: 'blur', message: this.$t('Tips.floatPriceCheck'),}
          ],
          materialMinpackageType: [

          ],
          materialMinpackageAmt: [
            {pattern:  /^([0-9]*)+\.{0,1}[0-9]{1,3}$/ , trigger: 'blur', message: this.$t('Tips.floatCheck'),}
          ],
          materialMinpackageTotalamt: [
            {pattern:  /^([0-9]*)+\.{0,1}[0-9]{1,3}$/ , trigger: 'blur', message: this.$t('Tips.floatCheck'),}
          ],
          materialTaxPrice: [
            {required: true, message: this.$t('Tips.checkMaterialTaxPrice'), trigger: 'blur'},
            {pattern:  /^([0-9]*)+\.{0,1}[0-9]{1,6}$/ , trigger: 'blur', message: this.$t('Tips.floatPriceCheck'),}
          ],
          materialTaxTotalprice: [
            {required: true, message:  this.$t('Tips.checkMaterialTaxTotalprice'), trigger: 'blur'},
            {pattern:  /^([0-9]*)+\.{0,1}[0-9]{1,6}$/ , trigger: 'blur', message: this.$t('Tips.floatPriceCheck'),}
          ],
          tax: [
            {required: false, message:  this.$t('Tips.checkMaterialTaxTotalprice'), trigger: 'blur'},
            {pattern:  /^([0-9]*)+\.{0,1}[0-9]{1,6}$/ , trigger: 'blur', message: this.$t('Tips.floatPriceCheck'),}
          ],
          materialVatPrice: [
            {required: true, message: this.$t('Tips.checkMaterialVatPrice'), trigger: 'blur'},
            {pattern:  /^([0-9]*)+\.{0,1}[0-9]{1,6}$/ , trigger: 'blur', message: this.$t('Tips.floatPriceCheck'),}
          ],
          materialVatTotalprice: [
            {required: true, message: this.$t('Tips.checkMaterialVatTotalprice'), trigger: 'blur'},
            {pattern:  /^([0-9]*)+\.{0,1}[0-9]{1,6}$/ , trigger: 'blur', message: this.$t('Tips.floatPriceCheck'),}
          ],
          materialRate: [
            {required: true, message: this.$t('Tips.checkMaterialRate'), trigger: 'blur'},
            {pattern:  /^([0-9]*)+\.{0,1}[0-9]{1,6}$/ , trigger: 'blur', message: this.$t('Tips.floatPriceCheck'),}
          ],
          materialCurrency: [
            {required: true, message: this.$t('Tips.checkMaterialCurrency'), trigger: 'change'}
          ],
          // countryCode: [
          //   {required: true, message: '请选择国家标志', trigger: 'change'}
          // ],
          confirmStatus: [

          ],
          // orderOutTotalAmount: [
          //   {pattern:  /^([0-9]*)+\.{0,1}[0-9]{1,2}$/ , trigger: 'blur', message: this.$t('Tips.floatCheck'),}
          // ],
          // materOutTotalAmount: [
          //   {pattern:  /^([0-9]*)+\.{0,1}[0-9]{1,2}$/ , trigger: 'blur', message: this.$t('Tips.floatCheck'),}
          // ],
          // residualAmount: [
          //   {pattern:  /^([0-9]*)+\.{0,1}[0-9]{1,2}$/ , trigger: 'blur', message: this.$t('Tips.floatCheck'),}
          // ],
          // trimAmount: [
          //   {pattern:  /^([0-9]*)+\.{0,1}[0-9]{1,2}$/ , trigger: 'blur', message: this.$t('Tips.floatCheck'),}
          // ],
          // stockAmount: [
          //   {pattern:  /^([0-9]*)+\.{0,1}[0-9]{1,2}$/ , trigger: 'blur', message: this.$t('Tips.floatCheck'),}
          // ],
          // differAmount: [
          //   {pattern:  /^([0-9]*)+\.{0,1}[0-9]{1,2}$/ , trigger: 'blur', message: this.$t('Tips.floatCheck'),}
          // ],
          // takeOverAmount: [
          //   {pattern:  /^([0-9]*)+\.{0,1}[0-9]{1,2}$/ , trigger: 'blur', message: this.$t('Tips.floatCheck'),}
          // ],
          deliveryAmount: [
            {pattern:  /^([0-9]*)+\.{0,1}[0-9]{1,3}$/ , trigger: 'blur', message: this.$t('Tips.floatCheck'),}
          ],
          surplusAmount: [
            {pattern:  /^([0-9]*)+\.{0,1}[0-9]{1,3}$/ , trigger: 'blur', message: this.$t('Tips.floatCheck'),}
          ],



        },
      }
    },
    mounted() {
      this.init()
    },
    methods: {
      async init() {
        await activityService.initData().then(resp=>{
          this.orderUnits=resp.data.result.orderUnits
          this.materialUnit=resp.data.result.orderUnits
          this.materialCategory=resp.data.result.mattertype
          this.materialRelationUnit=resp.data.result.orderUnits
          this.materialMinpackageType=resp.data.result.minpackageType
          this.materialCurrency=resp.data.result.currency
          this.countryCode=resp.data.result.countryCode
          this.confirmStatus=resp.data.result.orderStatus
          this.orderDetailType= resp.data.result.orderDetailTypes

        },error=>{});
        await activityService.getAllOrderCode({isBalance:0}).then(resp=>{
          this.orderCodeList=resp.data.resultList
        });
        if (this.mode == "EDIT") {
          await activityService.findOrderDetailInfo({id: this.id}).then(resp => {
            this.form = resp.data.result;
          }, err => {
            console.error(err);
          });
          await activityService.getOrderInfoByOrderCode({orderCode:this.form.orderCode,isBalance:0}).then(resp=>{
            this.materialCodeList=[];
            resp.data.resultList.forEach(item=>{
              this.materialCodeList.push(item.materialInfoEntity)
            });
          });
        }

      },
      async checkMaterialCode(materialCode){
        await activityService.checkOrderCodeAndMaterialCode({materialCode:materialCode}).then(resp=>{
          if (resp.data.code == "201") {
            activityService.getMaterialInfoByMaterialCode({materialCode:materialCode}).then(resp=>{
              this.form.materialCategory=resp.data.result.materialCategory;
              this.form.materialDescCn=resp.data.result.materialDescCn;
              this.form.materialDescEn=resp.data.result.materialDescEn;
              this.form.materialDescRn=resp.data.result.materialDescRn;
              this.form.materialUnit=resp.data.result.materialUnit;
              this.form.materialRelation=resp.data.result.materialRelation;
              this.form.materialRelationUnit=resp.data.result.materialRelationUnit;
              this.form.materialMinpackageType=resp.data.result.materialMinpackageType;
              this.form.materialMinpackageAmt=resp.data.result.materialMinpackageAmt;
              this.form.materialTaxPrice=resp.data.result.materialTaxPrice;
              this.form.materialVatPrice=resp.data.result.materialVatPrice;
              this.form.materialRate=resp.data.result.materialRate;
              this.form.materialCurrency=resp.data.result.materialCurrency;

            });
          } else {
            this.form.materialCategory="";
            this.form.materialDescCn="";
            this.form.materialDescEn="";
            this.form.materialDescRn="";
            this.form.materialUnit="";
            this.form.materialRelation="";
            this.form.materialRelationUnit="";
            this.form.materialMinpackageType="";
            this.form.materialMinpackageAmt="";
            this.form.materialTaxPrice="";
            this.form.materialVatPrice="";
            this.form.materialRate="";
            this.form.materialCurrency="";
            this.$notify({message: resp.data.message, type: "error"});
          }
        })
      },
      async checkOrderCode(orderCode){
        await activityService.checkOrderCodeAndMaterialCode({orderCode:orderCode,isBalance:0}).then(resp=>{
          if (resp.data.code == "201") {
            activityService.getOrderInfoByOrderCode({orderCode:orderCode,isBalance:0}).then(resp=>{
              this.materialCodeList=[];
              this.form.orderCodeDesc=resp.data.resultList[0] && resp.data.resultList[0].orderCodeDesc ||  "";
              this.form.orderDate=resp.data.resultList[0] && resp.data.resultList[0].orderDate ||  "";
              this.form.orderUnit=resp.data.resultList[0] && resp.data.resultList[0].orderUnit ||  "";
              this.form.orderAmount=resp.data.resultList[0] && resp.data.resultList[0].orderAmount ||  "";
              resp.data.resultList.forEach(item=>{
                this.materialCodeList.push(item.materialInfoEntity)
              });
            });
          } else {
            this.form.orderCodeDesc="";
            this.form.orderDate="";
            this.form.orderUnit="";
            this.form.orderAmount="";
            this.materialCodeList=[];
            this.$notify({message: resp.data.message, type: "error"});
          }
        })
      },
      searchOrderCode(queryString, cb){
        let result=this.orderCodeList.filter(item=>{
          return item.orderCode.indexOf(queryString) >= 0
        }).map(item=>{
          let data={};
          data.value=item.orderCode;
          return data
        });
        cb(result);
      },
      searchMaterialCode(queryString, cb){
        let result=this.materialCodeList.filter(item=>{
          return item.materialCode.indexOf(queryString) >= 0
        }).map(item=>{
          let data={};
          data.value=item.materialCode;
          return data
        });
        cb(result);
      },
      /*确定*/
      submit(formName) {
        this.$refs[formName].validate((valid) => {
          if (valid) {
            let data = {
              id                        :this.id                              || undefined,
              orderCode                 :this.form.orderCode                  || undefined,
              orderCodeDesc             :this.form.orderCodeDesc              || undefined,
              orderAmount               :this.form.orderAmount                ,
              orderDate                 :this.form.orderDate                  || undefined,
              orderUnit                 :this.form.orderUnit                  || undefined,
              orderId                   :this.form.orderId                    || undefined,
              orderIdItem               :this.form.orderIdItem                || undefined,
              materialCode              :this.form.materialCode               || undefined,
              materialDescCn            :this.form.materialDescCn             || undefined,
              materialDescEn            :this.form.materialDescEn             || undefined,
              materialDescRn            :this.form.materialDescRn             || undefined,
              materialSupplierNo        :this.form.materialSupplierNo         || undefined,
              materialUnit              :this.form.materialUnit               || undefined,
              materialAmount            :this.form.materialAmount             ,
              materialCategory          :this.form.materialCategory           || undefined,
              materialRelation          :this.form.materialRelation           || undefined,
              materialRelationUnit      :this.form.materialRelationUnit       || undefined,
              materialRelationQuantity  :this.form.materialRelationQuantity   ,
              materialMinpackageType    :this.form.materialMinpackageType     || undefined,
              materialMinpackageAmt     :this.form.materialMinpackageAmt      ,
              materialMinpackageTotalamt:this.form.materialMinpackageTotalamt ,
              materialTaxPrice          :this.form.materialTaxPrice           ,
              materialTaxTotalprice     :this.form.materialTaxTotalprice      ,
              tax                       :this.form.tax                        ,
              materialVatPrice          :this.form.materialVatPrice           ,
              materialVatTotalprice     :this.form.materialVatTotalprice      ,
              materialRate              :this.form.materialRate               ,
              materialCurrency          :this.form.materialCurrency           || undefined,
              countryCode               :this.form.countryCode                || undefined,
              confirmStatus             :this.form.confirmStatus              || undefined,
              orderOutTotalAmount       :this.form.orderOutTotalAmount        ,
              materOutTotalAmount       :this.form.materOutTotalAmount        ,
              residualAmount            :this.form.residualAmount             ,
              trimAmount                :this.form.trimAmount                 ,
              // stockAmount               :this.form.stockAmount               ,
              differAmount              :this.form.differAmount               ,
              takeOverAmount            :this.form.takeOverAmount             ,
              deliveryAmount            :this.form.deliveryAmount             ,
              surplusAmount             :this.form.surplusAmount              ,
              version                   :this.form.version                    || undefined,
              dataRoleAt                :this.form.dataRoleAt                 || undefined,
              orderDetailType           :this.form.orderDetailType            || undefined,
              isBalance                 :0,
              dateFlag                  :this.dateFlag                        || undefined
            };
            activityService.checkOrderCodeAndMaterialCode({orderCode:this.form.orderCode,materialCode:this.form.materialCode,isBalance:0}).then(resp=>{
              if (resp.data.code == "201") {
                if (this.mode == 'EDIT') {  //编辑
                    activityService.updateOrderDetailInfo({...data}).then(resp => {
                      if (resp.data.code == "201") {
                        this.$notify({message: resp.data.message, type: "success"});
                        this.$emit("success");
                        this.dialogFormVisible = false
                      } else {
                        this.$notify({message: resp.data.message, type: "error"});
                      }
                    })
                } else {
                    activityService.addOrderDetailInfo({...data}).then(resp => {  //添加
                      if (resp.data.code == "201") {
                        this.$notify({message: resp.data.message, type: "success"});
                        this.$emit("success");
                        this.dialogFormVisible = false
                      } else {
                        this.$notify({message: resp.data.message, type: "error"});
                      }
                    })
                }
              }else {
                this.$notify({message: resp.data.message, type: "error"});
              }
            });
          } else {
            console.log('error submit!!');
            return false;
          }
        });
      },
      cancel() {
        this.dialogFormVisible = false
      },
    }
  }
</script>

<style scoped>

</style>